<?php
/**
 * This class use the Original MySQL API to operate the database, 
 * This extension is deprecated as of PHP 5.5.0, and will be removed in the future. 
 * Instead, the MySQLi or PDO_MySQL extension should be used.
 * But if you can not install them in your server, then you can use this.
 * if the php still support them.
 * 
 * 
 * @author Micheal Luthor
 * @version 0.0.0
 *
 */
X::import('Framework.XDatabase.Schema.Mysql.OriginalAPI.MysqlDbManager');
X::import('Framework.XDatabase.Schema.Mysql.OriginalAPI.MysqlSqlBuilder');
X::import('Framework.XDatabase.Schema.Mysql.OriginalAPI.MysqlSqlRunner');
X::import('Framework.XDatabase.Schema.Mysql.OriginalAPI.MysqlTableManager');

class Database {
	/**
	 * @var MysqlDbManager
	 */
	public $DBManager;
	
	/**
	 * @var MysqlTableManager
	 */
	public $TableManager;

	/**
	 * @var MysqlSqlBuilder
	 */
	public $SqlBuilder;
	
	/**
	 * @return Mysql
	 */
	function __construct(){
		$this->DBManager = new MysqlDbManager();
		$this->DBManager->host = X::app()->config['database']['server'];
		$this->DBManager->user = X::app()->config['database']['user'];
		$this->DBManager->password = X::app()->config['database']['password'];
		$this->DBManager->database = X::app()->config['database']['defaultDB'];
		$this->DBManager->connect();
		
		$this->DBManager->select();
		
		$this->TableManager = new MysqlTableManager($this->DBManager->conLink);
		$this->SqlBuilder = new MysqlSqlBuilder($this->DBManager->conLink);
		
		return $this;
	}
}
